using AntDesign;
using AntDesign.Select.Internal;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using SE.PO.CInterface.DBProtocols.Areas;
using SE.PO.CInterface.DBProtocols.Sites;
using SE.PO.CInterface.Web.Models;
using SE.PO.CInterface.Web.Pages.Form;

namespace SE.PO.CInterface.Web.Pages.DB.Site
{
    public partial class AddSiteFrom
    {
        
        private List<SelectMode> _siteType = null!;
        private List<SelectMode> _nodeFeatures = null!;
        
            
        [Parameter]
        public EventCallback OnSuccess { get; set; }
            
        [Parameter]
        public EventCallback OnFailure { get; set; }
        
        [Parameter]
        public EventCallback OnCancel { get; set; }
        
        public Form<CreateUpdateSiteDto> Form;
        
        private CreateUpdateSiteDto _model = new();

        private readonly FormItemLayout _formItemLayout = new FormItemLayout
        {
            LabelCol = new ColLayoutParam
            {
                Xs = new EmbeddedProperty {Span = 24},
                Sm = new EmbeddedProperty {Span = 7},
            },

            WrapperCol = new ColLayoutParam
            {
                Xs = new EmbeddedProperty {Span = 24},
                Sm = new EmbeddedProperty {Span = 12},
                Md = new EmbeddedProperty {Span = 10},
            }
        };

        private readonly FormItemLayout _submitFormLayout = new FormItemLayout
        {
            WrapperCol = new ColLayoutParam
            {
                Xs = new EmbeddedProperty {Span = 24, Offset = 0},
                Sm = new EmbeddedProperty {Span = 10, Offset = 7},
            }
        };

        protected override async Task OnInitializedAsync()
        {
            //todo:init areas
           
            //todo:init 局站类型
            //todo:init 局站特征
        }

        
        private async Task OnFinish()
        {
            var dto = await Client.Post(_model);
            if (Form.Validate() && dto != null)
            {
                await OnSuccess.InvokeAsync();
            }
            else
            {
                await OnFailure.InvokeAsync();
            }
        }

        private async Task  OnFinishFailed(EditContext editContext)
        {
            await OnCancel.InvokeAsync();
        }
    }
}